import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class longxia here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Longxia extends Actor
{
    /**
     * Act - do whatever the longxia wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        move(6);
        randomMove();
        turnAtEdge();
        eat();
    }
    public void randomMove(){
        if(Greenfoot.getRandomNumber(100)>60){
           turn(Greenfoot.getRandomNumber(30)-15); 
        }
    }
    public void turnAtEdge(){
        if(isAtEdge()){
            turn(20);
        }
    }
    public void eat(){
        if(isTouching(Crab.class)){
            removeTouching(Crab.class);
            Greenfoot.playSound("slurp.wav");
            World w = getWorld();
            GreenfootImage bg = w.getBackground();
            Color yanse;
            yanse = bg.getColor();
            yanse = Color.RED;
            bg.setColor(yanse);
            Font font1 = bg.getFont();
            font1 = font1.deriveFont(150);
            bg.setFont(font1);
            bg.drawString("失败！",200,300);
            Greenfoot.stop();
        }
    }
}
